--[[ 编码: JX-108-16 名称: 巨星任务-巨星空料箱入库-点执行 作者:HAN 日期:2025-1-29 级别:项目 函数: ClickRun 功能: -- 巨星料箱初始化操作的一部分 -- 创建‘巨星空料箱入库’作业 更改记录: --]] jx_base= require( "jx_base" ) wms_cntr= require( "wms_container" ) wms_wh = require( "wms_wh" ) function ClickRun ( strLuaDEID ) local nRet, strRetInfo local strUserLogin, strUserName nRet, strUserLogin, strUserName = mobox.getCurUserInfo( strLuaDEID ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前操作人员信息失败! "..strUserLogin ) end -- 获取TOPVIEW的输入信息 nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_STATION_NO","S_CNTR_CODE" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end local obj_attrs = json.decode( strRetInfo ) local station = lua.Get_StrAttrValue( obj_attrs[1].value ) local cntr_code = lua.Get_StrAttrValue( obj_attrs[2].value ) if ( station == '' or cntr_code == '' ) then mobox.setInfo( strLuaDEID, "输入参数不完整,无法执行入库作业!") return end -- 检查一下空料箱是否存在,不存在创建 local strCondition, strUpdateSql local cntr nRet, cntr = wms_cntr.GetInfo( strLuaDEID, cntr_code ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取容器信息失败!"..cntr) end if ( cntr == '' ) then -- 没有这个容器系统创建一个容器 cntr = m3.AllocObject( strLuaDEID, "Container" ) cntr.code = cntr_code cntr.type = 2 -- 巨星料箱 cntr.source = "巨星" nRet, container = m3.CreateDataObj(strLuaDEID, cntr) if (nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1),"创建【容器】失败!"..container ) end else if ( cntr.type ~= 2 ) then mobox.setInfo( strLuaDEID, "料箱'"..cntr_code.."'的类型不正确, 巨星空料箱拉入库的料箱必须是容器类型!") return end -- 判断一下容器是否已经和货位绑定,有不能做空料箱入库 local loc_code = wms_wh.GetLocCodeByCNTR( strLuaDEID, cntr_code ) if ( loc_code ~= '') then mobox.setInfo( strLuaDEID, "料箱'"..cntr_code.."'的已经和货位'"..loc_code.."'绑定,不能做空料箱入库操作!") return end -- 巨星料箱 的空满状态设置为 2/满 strUpdateSql = "N_EMPTY_FULL = 0" strCondition = "S_CODE = '"..cntr_code.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Container", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【容器】状态息失败!"..strRetInfo ) end end -- 获取站点货位,站点货位定义在常量中 local loc_code = jx_base.Get_Station_Loc( strLuaDEID, station ) local loc nRet, loc = wms_wh.GetLocInfo( loc_code ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '获取货位信息失败! '..loc_code ) end -- 判断一下这个容器是否有正在执行中的 JX_Task,如果有报错 local strCondition = "S_CNTR_CODE = '"..cntr_code.."' AND N_B_STATE IN (0,1,5,6)" nRet, strRetInfo = mobox.getDataObjCount( strLuaDEID, "JX_Task", strCondition ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "getDataObjCount失败!"..strRetInfo ) end local nCount = lua.StrToNumber( strRetInfo ) if ( nCount > 0 ) then mobox.setInfo( strLuaDEID, "料箱'"..cntr_code.."'存在正在执行的作业!") return end -- 创建一个【巨星任务】,类型(入库) local jx_task = m3.AllocObject(strLuaDEID,"JX_Task") jx_task.task_type = "巨星空料箱入库" jx_task.b_state = 1 -- 作业启动 jx_task.station = station jx_task.start_wh_code = loc.wh_code jx_task.start_area_code = loc.area_code jx_task.start_loc_code = loc_code jx_task.cntr_code = cntr_code jx_task.operator_name = strUserName jx_task.operator = strUserLogin nRet, jx_task = m3.CreateDataObj( strLuaDEID, jx_task ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '创建【巨星任务】失败!'..jx_task ) end local operation local ext_info = {} ext_info.bs_type = "巨星任务" ext_info.bs_no = jx_task.sour_no nRet, operation = jx_base.Create_StorageOperation( strLuaDEID, "巨星", station, cntr_code, "巨星入库", ext_info ) if ( nRet ~= 0 ) then mobox.setInfo( strLuaDEID, operation ) return end strUpdateSql = "S_OP_CODE = '"..operation.code.."'" strCondition = "S_SOURNO = '"..jx_task.sour_no.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "JX_Task", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【巨星任务】信息失败!"..strRetInfo ) end mobox.setInfo( strLuaDEID, "系统已经成功创建了一个巨星空料箱入库作业'"..operation.code.."'") local action = { { action_type = "refresh", value = "" } } nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo ) end -- 【注意】如果上面的程序有入库作业产生需要对入库作业的终点获取加入库锁 nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, operation.end_loc_code, wms_base.Get_nConst( strLuaDEID, "锁类型-入库锁" ), "", operation.code, operation.op_def_name ) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "wms_LockLocation 失败!"..strRetInfo ) end end